﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;


namespace FineUI.Examples
{
    public partial class gridview : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
          //string  a = Request.QueryString["colleage_name"];
          //  string b = Request.QueryString["major_name"];

            //if (!IsPostBack)
            //{
            //    bind();
            //}
        }
        //protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        //{
        //    GridView1.PageIndex = e.NewPageIndex;
        //    bind();  //gridview绑定数据
        //}
        ////数据库的绑定
        //public void bind()
        //{
        //    SqlConnection con = gridview.createconnection();
        //    con.Open();
        //    string str = "select JH_kecheng.id,JH_major.colleage_name,JH_major.major_name,JH_kecheng.kecheng_name,JH_kecheng.a,JH_kecheng.b,JH_kecheng.c,JH_kecheng.d,JH_kecheng.e from JH_major,JH_kecheng,JH_connect where JH_major.id= JH_connect.m_id AND JH_kecheng.id=JH_connect.k_id AND JH_major.colleage_name='" + Request.QueryString["colleage_name"] + "' AND JH_major.major_name='" + Request.QueryString["major_name"] + "'";
        //    SqlCommand cmd = new SqlCommand(str, con);
        //    DataSet ds = new DataSet();
        //    SqlDataAdapter adp = new SqlDataAdapter(str, con);
        //    adp.Fill(ds);
        //    GridView1.DataSource = ds;
        //    GridView1.DataKeyNames = new string[] { "id" };//主键
        //    //GridView1.DataBind();
        //    this.GridView1.DataSource=ds.Tables[0].DefaultView;
        //    this.GridView1.DataBind();
        //    con.Close();
        //}
        //// 连接数据库的测试
        ////protected void test11(object sender, System.EventArgs e)
        ////{
        ////    SqlConnection con = gridview.createconnection();
        ////    con.Open();
        ////    string str = "select JH_major.colleage_name,JH_major.major_name,JH_kecheng.kecheng_name,JH_kecheng.a,JH_kecheng.b,JH_kecheng.c,JH_kecheng.d,JH_kecheng.e from JH_major,JH_kecheng,JH_connect where JH_major.id= JH_connect.m_id AND JH_kecheng.id=JH_connect.k_id AND JH_major.colleage_name='" + Request.QueryString["colleage_name"] + "' AND JH_major.major_name='" + Request.QueryString["major_name"]+ "'";
        ////    SqlCommand cmd = new SqlCommand(str, con);
        ////    DataSet ds = new DataSet();
        ////    SqlDataAdapter adp = new SqlDataAdapter(str, con);
        ////    adp.Fill(ds);
        ////    //GridView1.DataSource = ds;
        ////    //GridView1.DataKeyNames = new string[] { "JH_major.id,JH_kecheng.id" };//主键
        ////    //GridView1.DataBind();
        ////    Label3.Text = ds.Tables[0].Rows[1].ItemArray[4].ToString().Trim();
        ////    con.Close();
        ////    //string s_url;
        ////    //s_url = "gridview.aspx?colleage_name=" + Textbox1.Text + "&major_name=" + Textbox2.Text;
        ////    //Response.Redirect(s_url);
        ////    //Response.Write("<script>window.showModalDialog('gridview.aspx')</script>");
        ////    //Textbox1.Text = "";
        ////    //Textbox2.Text = "";
        ////    //SqlConnection con = gridview.createconnection();
        ////    //con.Open();
        ////    //string str = "select * from JH_colleage ";
        ////    //SqlCommand cmd = new SqlCommand(str,con);
        ////    //DataSet ds = new DataSet();
        ////    //SqlDataAdapter adp = new SqlDataAdapter(str, con);
        ////    //adp.Fill(ds, "colleage");
        ////    //Textbox1.Text = ds.Tables["colleage"].Rows[0].ItemArray[1].ToString().Trim();
        ////    //con.Close();
        ////}

        ////gridview的取消操作
        //protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        //{
        //    GridView1.EditIndex = -1;
        //    bind();
        //}
        ////gridview的更新操作
        //protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        //{
        //   // Label3.Text = GridView1.Rows[e.RowIndex].Cells[3].Text.ToString();

        //    //Label2.Text = GridView1.Rows[e.RowIndex].Cells[4].Text;
        //    //string tea = new DataKey(e.Keys).Value.ToString();
        //   // Label3.Text = GridView1.Rows[0].Cells[7].Text.ToString();
        //    SqlConnection con = gridview.createconnection();
        //    con.Open();
        //    string str = "update JH_kecheng set kecheng_name = '" + GridView1.Rows[0].Cells[2].Text.ToString() + "',a = '" + GridView1.Rows[0].Cells[3].Text.ToString() + "',b='" + GridView1.Rows[0].Cells[4].Text.ToString() + "',c='" + GridView1.Rows[0].Cells[5].Text.ToString() + "',d='" + GridView1.Rows[0].Cells[6].Text.ToString() + "',e='" + GridView1.Rows[0].Cells[7].Text.ToString() + "' where id='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
        //    SqlCommand cmd = new SqlCommand(str, con);
        //    //DataSet ds = new DataSet();
        //    //SqlDataAdapter adp = new SqlDataAdapter(str, con);
        //    //adp.Fill(ds);
        //    cmd.ExecuteNonQuery();
        //    GridView1.EditIndex = -1;
        //    bind();
        //    con.Close();
        //}
        ////gridview的编辑操作
        //protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        //{
        //    GridView1.EditIndex = e.NewEditIndex;
        //    bind();
        //}
        ////gridview的删除操作
        //protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        //{
        //    SqlConnection con = gridview.createconnection();
        //    string str = "delete JH_connect from JH_connect inner join JH_kecheng on JH_connect.k_id=JH_kecheng.id where JH_kecheng.id= '" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'delete JH_kecheng from JH_kecheng where JH_kecheng.id='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
        //    con.Open();
        //    SqlCommand cmd = new SqlCommand(str, con);       
        //    cmd.ExecuteNonQuery();         
        //    con.Close();
        //    bind();
        //}


        //////数据库连接类的创建
        //public static SqlConnection createconnection()
        //{
        //    string connectString = "Data Source=(local);Initial Catalog=ReportManagement;Integrated Security=True";
        //    SqlConnection con = new SqlConnection(connectString);
        //    return con;
        //}
    }
}